package ru.dc.gui.swing.util;


import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * Выводит число в формате размера файла (1 Gb итп).
 * <pre>
 * User: Penkov Vladimir
 * Date: 01.11.2010
 * Time: 13:26:21
 * </pre>
 */
public class SizeRenderer extends DefaultTableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (value instanceof Long) {
            label.setText(FileUtils.byteCountToDisplaySize((Long) value));
            label.setHorizontalAlignment(SwingConstants.RIGHT);
        }
        return label;
    }

}
